<template>
  <div class="updateHouse">
    <h3 class="title">修改房产信息</h3>
    <el-form
      :model="ruleForm"
      status-icon
      :rules="rules"
      ref="ruleForm"
      label-width="150px"
      class="demo-ruleForm"
    >
      <el-form-item label="所属人	" prop="master">
        <el-input v-model="ruleForm.item.master"></el-input>
      </el-form-item>
      <el-form-item label="房产地址" prop="houseAddress">
        <el-input disabled v-model="ruleForm.item.houseAddress"></el-input>
      </el-form-item>
      <el-form-item label="成交价" prop="price">
        <el-input v-model="ruleForm.item.price"></el-input>
      </el-form-item>
      <el-form-item label="成交日期" prop="fixtureTime">
        <el-date-picker
          v-model="ruleForm.item.fixtureTime"
          value-format="yyyy-MM-dd"
          type="date"
          placeholder="修改成交日期"
      ></el-date-picker>
      </el-form-item>
      <el-form-item label="产权" prop="propertyRight">
        <el-input v-model="ruleForm.item.propertyRight"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" :plain="true" @click="submitForm('ruleForm')"
          >保存</el-button
        >
        <el-button type="info" :plain="true" @click="close()">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import userRequest from "../request/user";
export default {
  props: ["item", "clearComp"],
  data() {
    var master = (rule, value, callback) => {
      if (value === "") {
        return callback(new Error("请填写所属人名称"));
      } else {
        return callback();
      }
    };
    var price = (rule, value, callback) => {
      if (value === "") {
        return callback(new Error("请填成交价"));
      } else {
        return callback();
      }
    };
   
    return {
      ruleForm: {
        item: this.item,
      },
      rules: {
        master: [{ validator: master, trigger: "blur" }],
        price: [{ validator: price, trigger: "blur" }],
      },
    };
  },

  methods: {
    close() {
      this.clearComp();
    },
    submitForm(ruleForm) {
      this.$refs[ruleForm].validate((valid) => {
        if (valid) {
          userRequest
            .addHouse({
              id: this.item.id,
              createTime: this.item.createTime,
              master: this.ruleForm.item.master,
              price: this.ruleForm.item.price,
              fixtureTime: this.ruleForm.item.fixtureTime,
              propertyRight: this.ruleForm.item.propertyRight
            })
            .then((res) => {
              if (res.data.success == true) {
                this.$message.success("修改成功!");
                this.clearComp();
              } else {
                this.$message.error(res.data.message);
              }
            });
        } else {
          this.$message.error("请检查信息是否完整！");
          return false;
        }
      });
    },
  },

  created() {
    console.log(this.item);
  },
};
</script>

<style lang="scss" scoped>
.updateHouse {
  overflow: hidden;

  ::v-deep .title {
    text-align: center;
    font-size: 20px;
  }
  ::v-deep .demo-ruleForm {
    width: 500px;
    margin: 30px auto;
  }
  ::v-deep .el-input__inner {
    height: 45px;
    font-size: 16px;
  }
  ::v-deep .el-form-item__label {
    font-size: 16px;
    position: relative;
    top: 10px;
  }
  ::v-deep .el-form-item__content {
    margin-top: 10px;
    height: 50px;
    display: flex;
  }
  ::v-deep .el-form-item__error {
    font-size: 16px;
  }

  ::v-deep .el-select-dropdown__item {
    display: flex;
    justify-content: center;
  }
  ::v-deep .el-radio-group {
    width: 100px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 11px;
  }
}
</style>